package 数据结构和算法.剑指offer.栈和队列.用两个栈实现队列;

import java.util.Stack;

public class Test {
    public static void main(String[] args) {

    }

    static class CQueue {
        private Stack<Integer> stack1;
        private Stack<Integer> stack2;
        private int size;

        public CQueue() {
            stack1 = new Stack();
            stack2 = new Stack();
            size = 0;
        }

        public void addDetail(int value) {
            stack1.push(value);
            size++;
        }

        public int deleteHead() throws Exception {
            if (stack2.isEmpty()) {
                while (!stack1.isEmpty()) {
                    stack2.push(stack1.pop());
                }
            }

            if (stack2.isEmpty()) {
                throw new Exception("队列为空，不能删除");
            }

            return stack2.pop();
        }
    }
}
